package httpconnect;

import com.sun.istack.internal.NotNull;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;

/**
 * Created by zy on 2018/10/17.
 */
public class MenuBean implements CallBack {
    @Override
    public void responseData(String data,@NotNull CallBack callBack) {
        Document document = Jsoup.parse(data);
        int i = 1;
        Element pElement = document.getElementById("list");
        Elements dElements = pElement.getElementsByTag("dd");
        for (Element element : dElements) {
            Elements aElements = element.getElementsByTag("a");
            for (Element aElement : aElements) {
                String s = aElement.attr("href");
                try {
                    String nodeData = HttpMethod.sendPost(Const.BaseUrl + s, null, null, null);//new File(element.text() + ".html"));
                    callBack.responseData(nodeData,null);
                    System.out.println(i++ + aElement.text());
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (KeyManagementException e) {
                    e.printStackTrace();
                } catch (NoSuchAlgorithmException e) {
                    e.printStackTrace();
                } catch (NoSuchProviderException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}
